#encoding=utf8
'''
Created on 2012-10-17

@author: Administrator
'''
from Processor import Processor
from pub import Func, UserDict;
from pub.Config import Config;
from models import UserModel;

class UPSClass(Processor):
    '''
    指令：UPS(user privace set) 
    备注：用户隐私设置
    格式：c-s:cmd#cmdID#userID#flag
     s-c:cmd#cmdID# result #msg
    '''
    def __init__(self):
        Processor.__init__(self);
        self.__userId = 0;
        self.__flag=0;

        
    def dataValidtor(self, cmdContent):
        if not cmdContent:
            return False;
        paraLen = len(cmdContent);
        if paraLen == 2:      
            self.__userId = Func.toInt(cmdContent[0]);
            self.__flag = Func.toInt(cmdContent[1]);

        
            return True;        
        return False;
    def outData(self,):
        user=UserDict.getUserFromUserDictById(self.__userId);
        userM=UserModel();
        sendData=[];
        if not user:
            user=userM.getUserInfoById(self.__userId,user);
        if not user:
            sendData.append(0);
            sendData.append(Config.I_USER_FIND_INFO_ERROR);
        else:
            sendData.append(1);
            sendData.append(Config.I_USER_FIND_INFO_SUSS);
            user.set_search_flag(self.__flag);
            userM.modifanInfo(user);
        
        Func.sendMsgStr(self._sockObj, self.setPackage(sendData));
        return True;
             
